/*
 *  txdnet.cn tonydon
 * 
 */
package cn.txdnet.txcms.view.action;

import cn.txdnet.txcms.query.ViewSiteListQuery;
import cn.txdnet.txcms.service.DHIndexService;
import cn.txdnet.txweb.model.ModelUtil;
import cn.txdnet.txweb.model.ModelView;
import cn.txdnet.txweb.utils.HttpUtil;
import cn.txdnet.txweb.utils.Message;
import cn.txdnet.txweb.utils.StringUtil;
import cn.txdnet.txweb.utils.WebUtil;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import txdnet.util.StaticMark;

/**
 *
 * @author txdnet
 */
public class DHIndexAction {

    /**
     * web多引擎搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView web_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("web_so", data);
    }

    /**
     * 新闻搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView news_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        data.put("gbk_word", StringUtil.encodeGBK(queryWord));
        return ModelUtil.getJspModel("news_so", data);
    }

    /**
     * mp3 搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView mp3_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        data.put("gbk_word", StringUtil.encodeGBK(queryWord));
        return ModelUtil.getJspModel("mp3_so", data);
    }

    /**
     * 视频搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView vod_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("vod_so", data);
    }

    /**
     * 图片搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView pic_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("pic_so", data);
    }

    /**
     * 问答搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView ask_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("ask_so", data);
    }

    /**
     * 文库 搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView wenku_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        data.put("gbk_word", StringUtil.encodeGBK(queryWord));
        return ModelUtil.getJspModel("wenku_so", data);
    }

    /**
     * 贴吧搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView tie_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("tie_so", data);
    }

    /**
     * 地图搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView map_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("map_so", data);
    }

    /**
     * 购物搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView buy_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        data.put("gbk_word", StringUtil.encodeGBK(queryWord));
        return ModelUtil.getJspModel("buy_so", data);
    }

    /**
     * 百科搜索
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView baike_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("baike_so", data);
    }

    /**
     * 翻译
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView fanyi_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("fanyi_so", data);
    }

    /**
     * 搜工作
     * @param req
     * @return
     * @throws Exception 
     */
    public ModelView job_so(HttpServletRequest req) throws Exception {
        String queryWord = WebUtil.clearXss(WebUtil.getNoNull(req, "q", StaticMark.STR_EMPTY));
        String selectSite = WebUtil.getArrStr(req, "sel", StaticMark.STR_EMPTY);
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("word", queryWord);
        data.put("site", selectSite);
        return ModelUtil.getJspModel("job_so", data);
    }

    /**
     * 下载快捷方式
     *
     * @return
     * @throws Exception
     */
    public ModelView down_shortcut() throws Exception {
//        String shortCutFile = WebUtil.WEB_APP_PATH.concat("/index/uuola.com.url");
//        InputStream is =  FileUtils.openInputStream(new File(shortCutFile));
//        return ModelUtil.getDownModel("噢啦网址导航.url", is);
        String shortCutContent = "[InternetShortcut]\r\nURL=http://www.uuola.com/?ref=shortcut\r\nIDList=\r\n[{000214A0-0000-0000-C000-000000000046}]\r\nProp3=19,2\r\n";
        return ModelUtil.getDownModel("噢啦网址导航.url", shortCutContent);
    }

    /**
     * 代理访问网站页面
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView proxy_get(HttpServletRequest req) throws Exception {
        String urlStr = WebUtil.getNoNull(req, "url", null);
        String encoding = WebUtil.getNoNull(req, "enc", StaticMark.ENCODING_UTF8);
        if (urlStr == null) {
            return ModelUtil.getTextModel(Message.MSG_PARAM_ERR);
        }
        String content = HttpUtil.doGet(urlStr, encoding, null, null);
        if (StringUtil.isEmpty(content)) {
            return ModelUtil.getTextModel(StaticMark.STR_EMPTY);
        }
        return ModelUtil.getTextModel(content);
    }

    /**
     * 导航站点分类列表
     *
     * @param req
     * @return
     * @throws Exception
     */
    public ModelView site_list(HttpServletRequest req) throws Exception {
        int cid = WebUtil.getInt(req, "c", -1);
        int rownum = WebUtil.getInt(req, "rn", 1024);
        int crow = WebUtil.getInt(req, "cr", 0);
        int listsize = WebUtil.getInt(req, "ls", 256);
        ViewSiteListQuery query = new ViewSiteListQuery();
        query.setCid(cid);
        query.setCrow(crow);
        query.setRownum(rownum);
        query.setListsize(listsize);
        Map page = DHIndexService.querySiteList(query);
        return ModelUtil.getJspModel("site_list", page);
    }
}
